package com.lac.component.rabbitmq.partition;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;

/**
 * @author xiaokuixiao
 * date2025/7/2 13:30
 */
@Configuration
public class RabbitMqPartitionConfig {

    @Bean
    public Queue partitionQueue0() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-single-active-consumer", true);
        return new Queue("partition_queue_0", true, false, false, args);
    }

    @Bean
    public Queue partitionQueue1() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-single-active-consumer", true);
        return new Queue("partition_queue_1", true, false, false, args);
    }

    @Bean
    public Queue partitionQueue2() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-single-active-consumer", true);
        return new Queue("partition_queue_2", true, false, false, args);
    }

    @Bean
    public TopicExchange partitionExchange() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-single-active-consumer", true);
        return new TopicExchange("partition_exchange");
    }

    @Bean
    public Binding binding0(Queue partitionQueue0, TopicExchange partitionExchange) {
        return BindingBuilder.bind(partitionQueue0).to(partitionExchange).with("partition.0");
    }

    @Bean
    public Binding binding1(Queue partitionQueue1, TopicExchange partitionExchange) {
        return BindingBuilder.bind(partitionQueue1).to(partitionExchange).with("partition.1");
    }

    @Bean
    public Binding binding2(Queue partitionQueue2, TopicExchange partitionExchange) {
        return BindingBuilder.bind(partitionQueue2).to(partitionExchange).with("partition.2");
    }
}
